<template>
	<div class="user_goods">
		<Tabs tabsOneTitle="关注的" tabsTwoTitle="我的" type="goods">
			<GroupsMessageList @setDataObject="setDataObject" @getFeedsHandle="getFeedsHandle" :feeds="goods" slot="user"></GroupsMessageList>
			<GroupsMessageList @setDataObject="setDataObject" @getFeedsHandle="getFollowFeedsHandle" :feeds="followerGoods" slot="follow"></GroupsMessageList>
		</Tabs>
	</div>
</template>
<script>
	const Cookie = window.Cookie();
	import Axios from "axios";
	import qs from "Qs";
	export default{
		name: "goods",
		data: function(){
			return {
				goods:[],
				followerGoods:[],
				currentUser:{}
			}
		},
		props:["id"],
		components:{
			GroupsMessageList: r => require.ensure([], () => r(require('../components/messagelist.vue')), 'groups_message_list'),
			Tabs: r => require.ensure([], () => r(require('../components/tabs.vue')), 'tabs')
		},
		watch:{
			goods:function(val){
				
			}
		},
		mounted:function(){
			const that = this;
			//console.log(this.$props.id)
			this.$emit("setDataObject", {type:"feeds", title:"动态", showTip:false})
			//console.log(this.$data.goods)
			//console.log(Cookie.get("userToken"))
			let userToken = Cookie.get("userToken");
			if (!userToken){
				this.$router.push('signin')
			}else{
				userToken = window.stringToJson(userToken, function(a){
					//console.log(a)
					that.$set(that, "currentUser", a);
				});
				this.getFeedsHandle();
				this.getFollowFeedsHandle();
			}
		},
		methods:{
			setDataObject(v){
				this.$emit("setDataObject", v);
			},
			getFollowFeedsHandle(){
				const that = this;
				that.$nextTick(()=>{
					Axios.post(this.$store.state.api.getFollowerMessage, qs.stringify({
						userid:this.$data.currentUser.id,
						username:this.$data.currentUser.name,
						email:this.$data.currentUser.email
					})).then((res) => {
						console.log(res)
						if (res.data.status === 1){
							let data = res.data.data;
							that.$set(that, "followerGoods", data)
						}else{
							
						}
					}).catch((err) => {
						console.log(err)
					})
				})
			},
			getFeedsHandle(){
				const that = this;
				that.$nextTick(()=>{
					Axios.post(this.$store.state.api.getUserMessage, qs.stringify({
						userid:this.$data.currentUser.id,
						username:this.$data.currentUser.name,
						email:this.$data.currentUser.email
					})).then((res) => {
						console.log(res)
						if (res.data.status === 1){
							let data = res.data.data.reverse();
							that.$set(that, "goods", data)
						}else{
							
						}
					}).catch((err) => {
						console.log(err)
					})
				})
			}
		}
	}
</script>
<style lang="less">
	@base:23.44/1rem;
	.user_goods{
		margin:70/@base 0 0;
		padding:0 0 70/@base 0;
	}
</style>